package at.dl.android.dota.adviser;

import android.app.Activity;

public abstract class ActivityWithDB extends Activity {
    private DataBaseHelper myDbHelper = null;
    
    protected DataBaseHelper getDataBaseHelper () {
        if ( myDbHelper == null ) {
            myDbHelper = new DataBaseHelper(getBaseContext());
            myDbHelper.openDataBase();
        }
        return myDbHelper;
    }
    
    @Override
    protected void onResume () {
        super.onResume();
        getDataBaseHelper();
    }
    
    @Override
    protected void onPause () {
        super.onPause();
        disconnectDB();
    }

    public void disconnectDB () {
        if ( myDbHelper != null ) {
            myDbHelper.close();
            myDbHelper = null;
        }
    }
}
